package com.starbaba.apiActivity.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.base.common.database.BaseDao;
import com.base.common.exception.AppException;
import com.base.common.util.StringUtils;
import com.starbaba.apiActivity.service.ApiActivityConfService;
import com.starbaba.core.web.page.PageResponse;
import com.starbaba.model.dictionary.Constant;
import com.tuanzi.server.loan_base.model.db.apiModel.ApiActivity;

@Component
public class ApiActivityConfServiceImpl implements ApiActivityConfService{
	
	@SuppressWarnings("deprecation")
    private static BaseDao dao = new BaseDao(Constant.POOL_LIFE);
	
	public List<ApiActivity> getDateList(int iDisplayStart, int iDisplayLength, PageResponse pageResponse, Map<String, Object> paramsMap){
		String apiId = (String) paramsMap.get("apiId");  //配置模板ID，主键
		String apiName = (String) paramsMap.get("apiName");  //配置模板名
		String thirdId = (String) paramsMap.get("thirdId");  //甲方ID
		String thirdName = (String) paramsMap.get("thirdName");  //甲方名称

		String sql = "SELECT * FROM loan_api_activity ac WHERE 1=1 ";
		
		String selectSql = "";
		if (!StringUtils.isEmpty(apiId)) {
            selectSql += " AND ac.id = " + apiId ;
        }
		if (!StringUtils.isEmpty(apiName)) {
			selectSql += " AND ac.api_name LIKE '%" +apiName + "%'";
		}
		if (!StringUtils.isEmpty(thirdId)) {
            selectSql += " AND ac.third_id = " + thirdId ;
        }
		if (!StringUtils.isEmpty(thirdName)) {
			selectSql += " AND ac.third_name LIKE '%" +thirdName + "%'";
		}

		sql += selectSql;
		sql += " order by ac.ctime desc limit " + iDisplayStart + " , " + iDisplayLength;

		String countSql = "select count(1) FROM loan_api_activity ac where 1=1 " + selectSql;
		
		List<ApiActivity> list = null;
		try {
			int count = dao.getInt(countSql);
			list = dao.list(sql, ApiActivity.class, new Object[] {});
			pageResponse.setITotalRecords(count);
			pageResponse.setITotalDisplayRecords(count);
		} catch (AppException e) {
			e.printStackTrace();
		}
		return list;
	}

}
